﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;

#nullable disable

namespace PasteLoggerBoard.EntityFrameworkCore.Migrations
{
    public partial class add_user_report : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "NumError",
                table: "PTDayReport");

            migrationBuilder.DropColumn(
                name: "NumException",
                table: "PTDayReport");

            migrationBuilder.DropColumn(
                name: "NumInfo",
                table: "PTDayReport");

            migrationBuilder.RenameColumn(
                name: "NumWarning",
                table: "PTDayReport",
                newName: "HitTime");

            migrationBuilder.AddColumn<string>(
                name: "LogLevel",
                table: "PTDayReport",
                type: "character varying(16)",
                maxLength: 16,
                nullable: true);

            migrationBuilder.CreateTable(
                name: "PTClientIpHourReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    ClientIp = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTClientIpHourReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTGradeInfo",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    Desc = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    IsEnable = table.Column<bool>(type: "boolean", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTGradeInfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTGradeRole",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    GradeId = table.Column<int>(type: "integer", nullable: false),
                    RoleId = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTGradeRole", x => x.Id);
                },
                comment: "角色绑定权限");

            migrationBuilder.CreateTable(
                name: "PTLevelDayReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    LogLevel = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLevelDayReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTLevelHourReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    DataTime = table.Column<long>(type: "bigint", nullable: false),
                    LogLevel = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTLevelHourReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTPathDayReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Path = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTPathDayReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTPathHourReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    DataTime = table.Column<long>(type: "bigint", nullable: false),
                    Path = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTPathHourReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTRoleInfo",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    Model = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    Name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    Role = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    Desc = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    IsEnable = table.Column<bool>(type: "boolean", nullable: false),
                    Sort = table.Column<int>(type: "integer", nullable: false),
                    FatherId = table.Column<int>(type: "integer", nullable: false),
                    Level = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTRoleInfo", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTStatusDayReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    StatusCode = table.Column<int>(type: "integer", nullable: false),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTStatusDayReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTStatusHourReport",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    AppName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    DataDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    DataTime = table.Column<long>(type: "bigint", nullable: false),
                    StatusCode = table.Column<int>(type: "integer", nullable: false),
                    HitTime = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTStatusHourReport", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "PTUserInfo",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false)
                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
                    UserName = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
                    UserHead = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
                    CreateDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
                    Desc = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    Email = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    PassWord = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
                    IsEnable = table.Column<bool>(type: "boolean", nullable: false),
                    Grade = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
                    GradeId = table.Column<int>(type: "integer", nullable: false, comment: "角色ID")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PTUserInfo", x => x.Id);
                },
                comment: "登录用户表");

            migrationBuilder.CreateIndex(
                name: "IX_PTClientIpHourReport_DataDate",
                table: "PTClientIpHourReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTGradeInfo_Name",
                table: "PTGradeInfo",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_PTLevelDayReport_DataDate",
                table: "PTLevelDayReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTLevelHourReport_DataDate",
                table: "PTLevelHourReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTPathDayReport_DataDate",
                table: "PTPathDayReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTPathHourReport_DataDate",
                table: "PTPathHourReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTStatusDayReport_DataDate",
                table: "PTStatusDayReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTStatusHourReport_DataDate",
                table: "PTStatusHourReport",
                column: "DataDate");

            migrationBuilder.CreateIndex(
                name: "IX_PTUserInfo_Email",
                table: "PTUserInfo",
                column: "Email",
                unique: true);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "PTClientIpHourReport");

            migrationBuilder.DropTable(
                name: "PTGradeInfo");

            migrationBuilder.DropTable(
                name: "PTGradeRole");

            migrationBuilder.DropTable(
                name: "PTLevelDayReport");

            migrationBuilder.DropTable(
                name: "PTLevelHourReport");

            migrationBuilder.DropTable(
                name: "PTPathDayReport");

            migrationBuilder.DropTable(
                name: "PTPathHourReport");

            migrationBuilder.DropTable(
                name: "PTRoleInfo");

            migrationBuilder.DropTable(
                name: "PTStatusDayReport");

            migrationBuilder.DropTable(
                name: "PTStatusHourReport");

            migrationBuilder.DropTable(
                name: "PTUserInfo");

            migrationBuilder.DropColumn(
                name: "LogLevel",
                table: "PTDayReport");

            migrationBuilder.RenameColumn(
                name: "HitTime",
                table: "PTDayReport",
                newName: "NumWarning");

            migrationBuilder.AddColumn<int>(
                name: "NumError",
                table: "PTDayReport",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "NumException",
                table: "PTDayReport",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "NumInfo",
                table: "PTDayReport",
                type: "integer",
                nullable: false,
                defaultValue: 0);
        }
    }
}
